﻿using System;
using System.IO;
using System.Linq;
using Wicresoft.Logger;
using Wicresoft.Task.Common;
using Wicresoft.Task.Team.Entity;


namespace Wicresoft.Task.Team
{
    public static class Helper
    {
        public static string ReadFile(string x)
        {
            string y = "";
            try
            {
                y = File.ReadAllText(x);
            }
            catch (Exception z)
            {
                Log.Info("读取文件错误", z.Message);
            }
            return y;
        }
        public static string ReturnWorkItemInfo(WorkItemInfo[] itemStr, TfsAutoNotifyContext TeamDB, ShelveInfo s)
        {
            string workItemInfor = "";
            string tempLink = Helper.ReadFile("Link.html");
            if (itemStr.Length != 0)
            {
                if (itemStr[0].WorkItemId == -1)
                {
                    workItemInfor = itemStr[0].Title;
                }
                else
                {
                    int j = 0;
                    foreach (var item in itemStr)
                    {
                        string _link = string.Format(tempLink, TeamDB.ProjectCollections.First(p => p.ProjectCollectionId == s.ProjectCollectionId).Value, item.WorkItemId, item.WorkItemId, item.Title);
                        int a = itemStr.Length;
                        if (j == a - 1)
                        {
                            workItemInfor = workItemInfor + _link;
                        }
                        else
                        {
                            workItemInfor = workItemInfor + _link + ",<br />";
                            j = j + 1;
                        }


                    }
                }
            }
            workItemInfor = workItemInfor + "<br />";
            return workItemInfor;
        }
        public static string ReturnChangeListInfo(ChangeListInfo[] itemStr)
        {
            string changeListInfor = "";
            string tempChange = Helper.ReadFile("ChangeList.html");
            if (itemStr.Length != 0)
            {
                if (itemStr[0].FileName == "UnChanged" || itemStr[0].ChangeType == "UnChanged")
                {
                    changeListInfor = "UnChanged";
                }
                else
                {
                    foreach (var item in itemStr)
                    {
                        string _link = string.Format(tempChange, item.FileName, item.ChangeType, item.LocalOrServerFolder);
                        changeListInfor = changeListInfor + _link;

                    }
                }
            }
            return changeListInfor;
        }
    }
}
